using System;
using System.Data;
using System.Collections;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.CarInsurance
{
    public class CarPreInsurerDB
    {
        public CarPreInsurerDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CarPreInsurer carpreinsurer)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocCarPreInsurerInsertUpdateSingleItem]";
            
            SortedList _sPara = new SortedList();
            
                #region Parameter
                _sPara.Add("@CarPreInsurerId", carpreinsurer.CarPreInsurerId);
                _sPara.Add("@CECarId", carpreinsurer.CECarId);
                _sPara.Add("@PreInsName", carpreinsurer.PreInsName);
                _sPara.Add("@VehicleNo", carpreinsurer.VehicleNo);
                _sPara.Add("@PolicyNo", carpreinsurer.PolicyNo);
                _sPara.Add("@ExpCanDate", carpreinsurer.ExpCanDate);
                _sPara.Add("@ViewedDetailId", carpreinsurer.ViewedDetailId);
                _sPara.Add("@Status", carpreinsurer.Status);
                _sPara.Add("@RefCEUserID", carpreinsurer.RefCEUserId);
                _sPara.Add("@Info1", carpreinsurer.Info1);
                _sPara.Add("@Info2", carpreinsurer.Info2);
                _sPara.Add("@Info3", carpreinsurer.Info3);
                _sPara.Add("@Info4", carpreinsurer.Info4);
                _sPara.Add("@Info5", carpreinsurer.Info5);
                _sPara.Add("@Info6", carpreinsurer.Info6);
                _sPara.Add("@Info7", carpreinsurer.Info7);
                _sPara.Add("@Info8", carpreinsurer.Info8);
                _sPara.Add("@Info9", carpreinsurer.Info9);
                _sPara.Add("@Info10", carpreinsurer.Info10);
                _sPara.Add("@Info11", carpreinsurer.Info11);
                _sPara.Add("@Info12", carpreinsurer.Info12);
                _sPara.Add("@Info13", carpreinsurer.Info13);
                _sPara.Add("@Info14", carpreinsurer.Info14);
                _sPara.Add("@Info15", carpreinsurer.Info15);
                _sPara.Add("@Info16", carpreinsurer.Info16);
                _sPara.Add("@Info17", carpreinsurer.Info17);
                _sPara.Add("@Info18", carpreinsurer.Info18);
                _sPara.Add("@Info19", carpreinsurer.Info19);
                _sPara.Add("@Info20", carpreinsurer.Info20);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        public CarPreInsurer GetCarPreInsurer(Int64 CarId, Int64 UserId)
        {
            CarPreInsurer _carpreinsurer = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarPreInsurerSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarID", CarId);
            _spara.Add("@RefCEUserId", UserId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _carpreinsurer = new CarPreInsurer();
                    _carpreinsurer = FillDataRecord(_dt);
                }
            }
            return _carpreinsurer;
        }

        private CarPreInsurer FillDataRecord(DataTable myDataTable)
        {
            CarPreInsurer myPreInsurer = new CarPreInsurer();
            myPreInsurer.CarPreInsurerId = Convert.ToInt64(myDataTable.Rows[0]["CarPreInsurerId"].ToString());
            myPreInsurer.CECarId = Convert.ToInt64(myDataTable.Rows[0]["CECarId"].ToString());
            myPreInsurer.PreInsName = myDataTable.Rows[0]["PreInsName"].ToString();
            myPreInsurer.VehicleNo = myDataTable.Rows[0]["VehicleNo"].ToString();
            myPreInsurer.PolicyNo = myDataTable.Rows[0]["PolicyNo"].ToString();
            myPreInsurer.ExpCanDate = Convert.ToDateTime(myDataTable.Rows[0]["ExpCanDate"].ToString());
            myPreInsurer.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            myPreInsurer.Status = myDataTable.Rows[0]["Status"].ToString();
            return myPreInsurer;
        }
        
    }
}